using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VICC_EXPAGE1
    {
        public DataRow Convert2ICC_EXPAGE1(DataRow dwInput, string ITXDBVERSION, bool IsConvert = false)
        {
            DataSet SResult = new DataSet();
            SResult = QueryICC_EXPAGE1(dwInput, 0);
            DataRow dwReturn = null;
            if (SResult.Tables[0].Rows.Count > 0)
            {
                dwReturn = SResult.Tables[0].Rows[0];
            }
            else
            {
                dwReturn = SResult.Tables[0].NewRow();
            }
            switch (ITXDBVERSION)
            {
                case "YGR":
                    #region=========
         dwReturn["A"] = " ".PadRight(2 ); 
         dwReturn["B"] = " ".PadRight(2 ); 
         dwReturn["C"] = " ".PadRight(2 ); 
         dwReturn["D"] = " ".PadRight(2 ); 
         dwReturn["E"] = " ".PadRight(2 ); 
         dwReturn["F"] = " ".PadRight(2 ); 
         dwReturn["G"] = " ".PadRight(2 ); 
         dwReturn["H"] = " ".PadRight(2 ); 
         dwReturn["I"] = " ".PadRight(2 ); 
         dwReturn["J"] = " ".PadRight(2 ); 
         dwReturn["K"] = " ".PadRight(2 ); 
         dwReturn["L"] = " ".PadRight(2 ); 
         dwReturn["M"] = " ".PadRight(2 ); 
         dwReturn["N"] = " ".PadRight(2 ); 
         dwReturn["O"] = " ".PadRight(2 ); 
         dwReturn["P"] = " ".PadRight(2 ); 
         dwReturn["Q"] = " ".PadRight(2 ); 
         dwReturn["R"] = " ".PadRight(2 ); 
         dwReturn["S"] = " ".PadRight(2 ); 
         dwReturn["T"] = " ".PadRight(2 ); 
         dwReturn["U"] = " ".PadRight(2 ); 
         dwReturn["V"] = " ".PadRight(2 ); 
         dwReturn["W"] = " ".PadRight(2 ); 
         dwReturn["X"] = " ".PadRight(2 ); 
         dwReturn["Y"] = " ".PadRight(2 ); 
         dwReturn["Z"] = " ".PadRight(2 ); 
         dwReturn["AA"] = " ".PadRight(2 ); 
         dwReturn["AB"] = " ".PadRight(2 ); 
         dwReturn["AC"] = " ".PadRight(2 ); 
         dwReturn["AD"] = " ".PadRight(2 ); 
         dwReturn["AE"] = " ".PadRight(2 ); 
         dwReturn["AF"] = " ".PadRight(2 ); 
         dwReturn["AG"] = " ".PadRight(2 ); 
         dwReturn["AH"] = " ".PadRight(2 ); 
         dwReturn["AI"] = " ".PadRight(2 ); 
                    #endregion
                    break;
                case "JLT":

                    break;
                default:

                    break;
            }
            if (IsConvert)
            {
                foreach (DataColumn cm in dwInput.Table.Columns)
                {
                    if (dwInput[cm.ColumnName].ToString() == "")
                        continue;
                    if (dwReturn.Table.Columns.Contains(cm.ColumnName))
                    {
                        dwReturn[cm.ColumnName] = dwInput[cm.ColumnName];
                    }
                }
            }
            return dwReturn;
        }
        public void MapICC_EXPAGE1(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveICC_EXPAGE1(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryICC_EXPAGE1(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapICC_EXPAGE1(ref dwLocal, dwData);

            if (!flgExist)
            {

                InsertICC_EXPAGE1(dwLocal, ITXDBVERSION);
            }
            UpdateICC_EXPAGE1(dwLocal);
        }
        public void InsertICC_EXPAGE1(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                case "YGR":
                    or1.CommandText = "INSERT INTO ICC_EXPAGE1(VAKBMANDANT, VAKBKOLL, VAKBART, VAKBKUNDNR, VAKBFARBE, VAKBKDARTNR, VAKBKDARTBEZ, VAKBKDFARBNR, VAKBANDRUCK, VAKBMEGEW, VAKBMENGEH, VAKBGEWVON, VAKBGEWBIS, VAKBGEWCA, VAKBGEWFKT, VAKBGEWGRP, VAKBMEGFKT, VAKBMEGGRP, VAKBAENDZL, VAKBAENDBEN, VAKBAENDDAT, VAKBNEUBEN, VAKBNEUDAT, VAKBFILLER)"
                        + " VALUES (:VAKBMANDANT, :VAKBKOLL, :VAKBART, :VAKBKUNDNR, :VAKBFARBE, '                         ', '                         ', '                             ', ' ', '   ', '   ', 0, 0, ' ', '000000000000', ' ', '000000000000', ' ', 0, '        ', '000000', '        ', '      ', '                                          ')";
                    or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                //VAFMANDANT VAFKOLL VAFART VAFFARBE VAFBEZ VAFFFARBE

            }
            
            Connect2Proxy(or1);
        }
        public DataSet QueryICC_EXPAGE1(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM ICC_EXPAGE1 WHERE  ROWNUM<2 ";
                    break;
              
                case 99:
                    or1.CommandText = "SELECT * FROM ICC_EXPAGE1  WHERE ROWNUM<50";
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "ICC_EXPAGE1";
            Return = Result;
            return Return;
        }
        public void DeleteICC_EXPAGE1(DataRow dwData, int option = 1)
        {

            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM ICC_EXPAGE1   WHERE  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                     or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        } 
      
        public void UpdateICC_EXPAGE1(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    #region====Command==== 
                    or1.CommandText = "UPDATE ICC_EXPAGE1 SET "
                    +"A= :A,"
                    +"B= :B,"
                    +"C= :C,"
                    +"D= :D,"
                    +"E= :E,"
                    +"F= :F,"
                    +"G= :G,"
                    +"H= :H,"
                    +"I= :I,"
                    +"J= :J,"
                    +"K= :K,"
                    +"L= :L,"
                    +"M= :M,"
                    +"N= :N,"
                    +"O= :O,"
                    +"P= :P,"
                    +"Q= :Q,"
                    +"R= :R,"
                    +"S= :S,"
                    +"T= :T,"
                    +"U= :U,"
                    +"V= :V,"
                    +"W= :W,"
                    +"X= :X,"
                    +"Y= :Y,"
                    +"Z= :Z,"
                    +"AA= :AA,"
                    +"AB= :AB,"
                    +"AC= :AC,"
                    +"AD= :AD,"
                    +"AE= :AE,"
                    +"AF= :AF,"
                    +"AG= :AG,"
                    +"AH= :AH,"
                    +"AI= :AI,"
                        + " WHERE  "
                        + "  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                    #endregion

                    #region====Parameters====
          or1.Parameters.Add("A", OracleType.NVarChar).Value = dwData["A"].ToString(); 
          or1.Parameters.Add("B", OracleType.NVarChar).Value = dwData["B"].ToString(); 
          or1.Parameters.Add("C", OracleType.NVarChar).Value = dwData["C"].ToString(); 
          or1.Parameters.Add("D", OracleType.NVarChar).Value = dwData["D"].ToString(); 
          or1.Parameters.Add("E", OracleType.NVarChar).Value = dwData["E"].ToString(); 
          or1.Parameters.Add("F", OracleType.NVarChar).Value = dwData["F"].ToString(); 
          or1.Parameters.Add("G", OracleType.NVarChar).Value = dwData["G"].ToString(); 
          or1.Parameters.Add("H", OracleType.NVarChar).Value = dwData["H"].ToString(); 
          or1.Parameters.Add("I", OracleType.NVarChar).Value = dwData["I"].ToString(); 
          or1.Parameters.Add("J", OracleType.NVarChar).Value = dwData["J"].ToString(); 
          or1.Parameters.Add("K", OracleType.NVarChar).Value = dwData["K"].ToString(); 
          or1.Parameters.Add("L", OracleType.NVarChar).Value = dwData["L"].ToString(); 
          or1.Parameters.Add("M", OracleType.NVarChar).Value = dwData["M"].ToString(); 
          or1.Parameters.Add("N", OracleType.NVarChar).Value = dwData["N"].ToString(); 
          or1.Parameters.Add("O", OracleType.NVarChar).Value = dwData["O"].ToString(); 
          or1.Parameters.Add("P", OracleType.NVarChar).Value = dwData["P"].ToString(); 
          or1.Parameters.Add("Q", OracleType.NVarChar).Value = dwData["Q"].ToString(); 
          or1.Parameters.Add("R", OracleType.NVarChar).Value = dwData["R"].ToString(); 
          or1.Parameters.Add("S", OracleType.NVarChar).Value = dwData["S"].ToString(); 
          or1.Parameters.Add("T", OracleType.NVarChar).Value = dwData["T"].ToString(); 
          or1.Parameters.Add("U", OracleType.NVarChar).Value = dwData["U"].ToString(); 
          or1.Parameters.Add("V", OracleType.NVarChar).Value = dwData["V"].ToString(); 
          or1.Parameters.Add("W", OracleType.NVarChar).Value = dwData["W"].ToString(); 
          or1.Parameters.Add("X", OracleType.NVarChar).Value = dwData["X"].ToString(); 
          or1.Parameters.Add("Y", OracleType.NVarChar).Value = dwData["Y"].ToString(); 
          or1.Parameters.Add("Z", OracleType.NVarChar).Value = dwData["Z"].ToString(); 
          or1.Parameters.Add("AA", OracleType.NVarChar).Value = dwData["AA"].ToString(); 
          or1.Parameters.Add("AB", OracleType.NVarChar).Value = dwData["AB"].ToString(); 
          or1.Parameters.Add("AC", OracleType.NVarChar).Value = dwData["AC"].ToString(); 
          or1.Parameters.Add("AD", OracleType.NVarChar).Value = dwData["AD"].ToString(); 
          or1.Parameters.Add("AE", OracleType.NVarChar).Value = dwData["AE"].ToString(); 
          or1.Parameters.Add("AF", OracleType.NVarChar).Value = dwData["AF"].ToString(); 
          or1.Parameters.Add("AG", OracleType.NVarChar).Value = dwData["AG"].ToString(); 
          or1.Parameters.Add("AH", OracleType.NVarChar).Value = dwData["AH"].ToString(); 
          or1.Parameters.Add("AI", OracleType.NVarChar).Value = dwData["AI"].ToString(); 
                    #endregion
                    break; 
                default:
                    break;
            }


            Connect2Proxy(or1);
        }
    }
}
